<?php

/**
 * Created by EPP.
 * User: yuxun
 * Date: 18/6/26
 * Time: 21:21
 */
class NoticeTempletService extends Service{

    public static function indexHeader(){
        $header = array(
        		'id'          =>array('text' => 'ID', 'width' => '70px'),
        		'name'        => array('text' => '名称', 'width' => '150px'),
        		'title'       => array('text' => '标题', 'width' => '150px'),
                'content'     => array('text' => '内容', 'width' => '350px'),
                'create_time' => array('text' => '创建时间', 'width' => '150px'),
                'action'      => array('text' => '操作', 'width' => '150px'),
        );

        return $header;
    }

    public static function indexData($params){
        $modNoticeTemplet = new ModNoticeTemplet();
        $result = $modNoticeTemplet->select($params);

        foreach($result as &$v){
        	$v['content'] = '<div style="white-space:normal;">'.$v['content'].'</div>';
            $v['create_time']     = date('Y-m-d H:i:s', $v['create_time']);
            $v['action']        = ' <a href="'.PubFunc::buildUrl('/oss/?r=noticeTemplet/edit').'&id='.$v['id'].'">编辑</a>';
            $v['action']        .= ' <a href="'.PubFunc::buildUrl('/oss/?r=noticeTemplet/delete').'&id='.$v['id'].'" confirm="是否要删除该条信息?">删除</a>';            
        }
        unset($v);

        return $result;
    }

    public static function doAdd($params){
        $user = AccAuth::me();

        $modNoticeTemplet = new ModNoticeTemplet();

        $modNoticeTemplet->platform      = 'test';
        $modNoticeTemplet->game          = $params['g'];
        $modNoticeTemplet->name          = $params['name'];
        $modNoticeTemplet->title         = $params['title'];
        $modNoticeTemplet->content       = $params['content'];
        $modNoticeTemplet->create_user   = $user['UserID'];
        $modNoticeTemplet->create_time   = time();
        $modNoticeTemplet->update_user   = $user['UserID'];
        $modNoticeTemplet->update_time   = time();

        return $modNoticeTemplet->save();
    }

    public static function doEdit($id, $params){
        if(empty($id)) return false;

        $user = AccAuth::me();

        $modNoticeTemplet = new ModNoticeTemplet();
        $update = array();
        $update['platform']      = 'test';
        $update['game']          = $params['g'];
        $update['name']          = $params['name'];
        $update['title']         = $params['title'];
        $update['content']       = $params['content'];

        $update['update_user']   = $user['UserID'];
        $update['update_time']   = time();

        $modNoticeTemplet->updateByPk($id, $update);
        return true;
    }
    
    public static function get($id){
    	$modNoticeTemplet = new ModNoticeTemplet();
    	$obj = $modNoticeTemplet->findByPk($id);
    
    	if($obj){
    		$info = $obj->getAttributes();
    		return $info;
    	}else{
    		return false;
    	}
    }
    
    public static function delete($id){
    	if(empty($id)) return false;
    
    	$modNoticeTemplet = new ModNoticeTemplet();
    	$modNoticeTemplet->deleteByPk($id);
    	return true;
    }
    
    public static function lists(){
    	$params = array();
    	$game = PubBase::getCurrentGame();
    	$params['g'] = $game;
    	$modNoticeTemplet = new ModNoticeTemplet();
    	$lists = $modNoticeTemplet->select($params);
    	$data = array();
    	foreach ($lists as $key=>$val){
    		$data[$val['id']] = $val['name'];
    	}
    	return $data;

    }

    


}